function like(btn, entityType, entityId, entityUserId, discussPostId) {

    // 发送AJAX请求之前, 将CSRF令牌设置到请求头中
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });

    $.post(
        CONTEXT_PATH + "/like",
        {"entityType":entityType, "entityId":entityId, "entityUserId":entityUserId, "discussPostId":discussPostId},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0) {
                $(btn).children("i").text(data.likeCount);
                $(btn).children("b").text(data.likeStatus === 1 ? '已赞' : '赞');
            }
            else {
                alert(data.msg);
            }
        }
    );
}

$(function(){
    $("#top-btn").click(setTop);
    $("#wonderful-btn").click(setWonderful);
    $("#delete-btn").click(setDelete);
});

// 置顶方法
function setTop() {
    // 发送AJAX请求之前, 将CSRF令牌设置到请求头中
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });
    $.post(
        CONTEXT_PATH + "/discuss/top",
        {"discussPostId": $("#discussPostId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0) {
                $("#top-btn").attr("disabled", "disabled");
            }
            else {
                alert(data.msg);
            }
        }
    )
}

// 加精
function setWonderful() {
    // 发送AJAX请求之前, 将CSRF令牌设置到请求头中
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });
    $.post(
        CONTEXT_PATH + "/discuss/wonderful",
        {"discussPostId": $("#discussPostId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0) {
                $("#wonderful-btn").attr("disabled", "disabled");
            }
            else {
                alert(data.msg);
            }
        }
    )
}

// 删除
function setDelete() {
    // 发送AJAX请求之前, 将CSRF令牌设置到请求头中
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });
    $.post(
        CONTEXT_PATH + "/discuss/delete",
        {"discussPostId": $("#discussPostId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0) {
                // 跳转到首页
                location.href = CONTEXT_PATH + "/index";
            }
            else {
                alert(data.msg);
            }
        }
    )
}